package 牛客_面试必刷.Month07.day10;

public class 二叉树中和为某一值的路径_1 {

    public boolean hasPathSum (TreeNode root, int sum) {
        // write code here
        return solve(root,sum);
    }
    public boolean solve(TreeNode root,int sum){
        if(root == null) return false;
        if(root.left == null && root.right == null){
            if(sum - root.val == 0) return true;
            return false;
        }
        return solve(root.left,sum - root.val) || solve(root.right,sum - root.val);
    }
}
